<?php

require_once 'FileUploadView.php';
require_once 'FileUploadHandler.php';

class FileUploadController{
	
	public function DoControll()
	{
		$FileUploadView = new FileUploadView();
		$FileUploadHandler = new FileUploadHandler();

		$message = $FileUploadView->Message(FileUploadView::NO_MESSAGE);

		$output = $FileUploadView->CreateUploadForm();

		if($FileUploadView->TriedToUpload()){
			$File = $FileUploadView->GetFile();			

			if ($FileUploadHandler->CheckFile($File) == true) {
				$FileUploadHandler->SaveFile($File);
				$message = $FileUploadView->Message(FileUploadView::SUCCESS);
			}
			else{
				$message = $FileUploadView->Message(FileUploadView::WRONG_TYPE);				
			}

			if($File["name"] == ""){
				$message = $FileUploadView->Message(FileUploadView::NO_FILE_SELECTED);
			}
		}
		$output .= $message;
		return $output;		
	}
}
